// Configuration.cs created with MonoDevelop
// User: ikex at 7:39 A 13/09/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.Diagnostics;
using Mono.Data.SqliteClient;
using System.Data;
namespace snippetmanager
{
	public partial class Configuration : Gtk.Dialog
	{
		MainWindow that;
		public Configuration()
		{
			this.Build();
		}
		public void setup(MainWindow that){
			this.that = that; /* couldn't help myself */
		}
		protected virtual void OnButtonCancelClicked (object sender, System.EventArgs e)
		{
			this.Hide();
		}

		protected virtual void OnButtonOkClicked (object sender, System.EventArgs e)
		{
			dbaseconnection("DELETE FROM userinfo"); /* Should only be one entry? */
			dbaseconnection("INSERT INTO userinfo (username,password) VALUES ('"+entry2.Text.Replace("'","''")+"','"+entry3.Text.Replace("'","''")+"')");
			Console.WriteLine("Updated your username + pass to: "+entry2.Text+" + "+entry3.Text);
			//this.that.login();
			//this.Hide();
		}

		protected virtual void OnButton9Clicked (object sender, System.EventArgs e)
		{
			System.Diagnostics.Process.Start("http://ikex.ath.cx:1010/work/snippetmanager/createaccount.php");
		}
		/// <summary>
		/// Create a database connection and run the command {sql}
		/// </summary>
		/// <param name="sql">
		/// A <see cref="System.String"/>
		/// </param>
		/// <returns>
		/// A <see cref="IDataReader"/>
		/// </returns>
		public IDataReader dbaseconnection (string sql){
		   string connectionString = "URI=file:SnippetCode.db,version=3";
	       IDbConnection dbcon;
	       dbcon = (IDbConnection) new SqliteConnection(connectionString);
	       dbcon.Open();
		   // http://lists.ximian.com/pipermail/mono-patches/2005-June/059950.html
			//Mono.Data.SqliteClient
		   // ---
	       IDbCommand dbcmd = dbcon.CreateCommand();
	       Console.WriteLine("DEBUG SQL: "+sql);
	       dbcmd.CommandText = sql;
			dbcmd.Prepare();
	       IDataReader reader = dbcmd.ExecuteReader();
		
		   return reader;
		}
	}
}
